#!/bin/bash

vmlist=`ssh openstack@172.16.0.1 'source OpenStackInstaller/demorc && nova list | grep ACTIVE | tr -s \  | cut -d \  -f 4 | sort'`;



for vm in `echo $vmlist`
do
    # get address of a vm 
    vmaddress=`ssh openstack@172.16.0.1 'source OpenStackInstaller/demorc && nova show $vm | grep vmnet | tr -s \  | cut -d \  -f 6'`;
    # get load string and start loader on vm
    read line
    random=$(echo $line | grep 'random')
    if [[ "$random" ]]
    then
        echo $vm randomloader.sh
        ssh cirros@$vmaddress 'nohup randomloader.sh &> /dev/null &'
    else
        echo $vm loader.sh $line
        ssh cirros@$vmaddress 'nohup loader.sh $line &> /dev/null &'
    fi
done < "loads.txt"
